<?php

namespace App\Http\Resources\Kms\App;

use App\Models\Kms\App\ClientsAuthModel;
use App\Models\Kms\App\ClientsModel;
use Illuminate\Http\Resources\Json\JsonResource;

class ClientsListBackendResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            "id"             => $this->id,
            "icon"           => $this->icon,
            "name"           => $this->name,
            "desc"           => $this->desc,
            "sort"           => $this->sort,
            "type"           => $this->type,
            "childType"      => $this->childType,
            "authType"       => $this->authType,
            "authTypeText"   => translateEnumCodeToCn(ClientsModel::AUTH_TYPE_TEXT, $this->authType, "-"),
            "uniAppId"       => $this->uniAppId,
            "clientId"       => $this->clientId,
            "status"         => $this->status,
            "version"        => $this->clientsVersionRel,
            "authUser"       => $this->getAuthUser(),
            "authDepartment" => $this->getAuthDepartment()
        ]; // TODO=> Change the autogenerated stub
    }

    /**
     * @return array
     */
    public function getAuthUser(): array
    {
        $authUser = [];
        $this->clientsAuthFsUser->each(function (ClientsAuthModel $clientsAuthModel) use (&$authUser) {
            array_push($authUser, $clientsAuthModel->fsUserRel);
        });
        return $authUser;
    }

    /**
     * @return array
     */
    public function getAuthDepartment(): array
    {
        $authDepartment = [];
        $this->clientsAuthFsDepartment->each(function (ClientsAuthModel $clientsAuthModel) use (&$authDepartment) {
            array_push($authDepartment, $clientsAuthModel->fsDepartmentRel);
        });
        return $authDepartment;
    }

}
